widget-factory: Show some 'standard' dialog types
authorMatthias Clasen <mclasen@redhat.com>
Thu, 5 Jun 2014 22:07:32 +0000 (18:07 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 5 Jun 2014 22:08:45 +0000 (18:08 -0400)
Add examples for the types of dialog that are mentioned
in the GNOME HIG: information dialogs, action dialogs and
preference dialogs.

demos/widget-factory/widget-factory.c
demos/widget-factory/widget-factory.ui

index 0be65c7b1090eb78e3acd562bf548e2171738dda..d426725ca72ebd96dac7f98d0559357896fabe2c 100644 (file)
@@ -269,12 +269,25 @@ info_bar_response (GtkWidget *infobar, gint response_id)
     gtk_widget_hide (infobar);
 }
 
+static void
+show_dialog (GtkWidget *button, GtkWidget *dialog)
+{
+  gtk_widget_show (dialog);
+}
+
+static void
+close_dialog (GtkWidget *dialog)
+{
+  gtk_widget_hide (dialog);
+}
+
 static void
 activate (GApplication *app)
 {
   GtkBuilder *builder;
   GtkWindow *window;
   GtkWidget *widget;
+  GtkWidget *dialog;
   GtkAdjustment *adj;
   static GActionEntry win_entries[] = {
     { "dark", NULL, NULL, "false", change_theme_state },
@@ -282,9 +295,12 @@ activate (GApplication *app)
     { "search", activate_search, NULL, NULL, NULL },
     { "delete", activate_delete, NULL, NULL, NULL }
   };
+  GError *error = NULL;
 
   builder = gtk_builder_new ();
-  gtk_builder_add_from_resource (builder, "/ui/widget-factory.ui", NULL);
+  gtk_builder_add_from_resource (builder, "/ui/widget-factory.ui", &error);
+  if (error)
+    g_print ("error: %s\n", error->message);
   gtk_builder_add_callback_symbol (builder, "on_entry_icon_release", (GCallback)on_entry_icon_release);
   gtk_builder_connect_signals (builder, NULL);
 
@@ -320,6 +336,21 @@ activate (GApplication *app)
   g_signal_connect (widget, "response", G_CALLBACK (info_bar_response), NULL); 
   g_object_set_data (G_OBJECT (window), "infobar", widget);
 
+  dialog = (GtkWidget *)gtk_builder_get_object (builder, "info_dialog");
+  g_signal_connect (dialog, "response", G_CALLBACK (close_dialog), NULL);
+  widget = (GtkWidget *)gtk_builder_get_object (builder, "info_dialog_button");
+  g_signal_connect (widget, "clicked", G_CALLBACK (show_dialog), dialog);
+
+  dialog = (GtkWidget *)gtk_builder_get_object (builder, "action_dialog");
+  g_signal_connect (dialog, "response", G_CALLBACK (close_dialog), NULL);
+  widget = (GtkWidget *)gtk_builder_get_object (builder, "action_dialog_button");
+  g_signal_connect (widget, "clicked", G_CALLBACK (show_dialog), dialog);
+
+  dialog = (GtkWidget *)gtk_builder_get_object (builder, "preference_dialog");
+  g_signal_connect (dialog, "response", G_CALLBACK (close_dialog), NULL);
+  widget = (GtkWidget *)gtk_builder_get_object (builder, "preference_dialog_button");
+  g_signal_connect (widget, "clicked", G_CALLBACK (show_dialog), dialog);
+
   gtk_widget_show_all (GTK_WIDGET (window));
 
   g_object_unref (builder);
index d1870758a337db448078c339bfabeaa1a12ab0d5..1d8a50cd28c08b244b8c067801c86a3d864a581c 100644 (file)
@@ -2693,6 +2693,24 @@ Suspendisse feugiat quam quis dolor accumsan cursus. </property>
                             </child>
                           </object>
                         </child>
+                        <child>
+                          <object class="GtkButton" id="info_dialog_button">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">Inform</property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkButton" id="action_dialog_button">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">Act</property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkButton" id="preference_dialog_button">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">Configure</property>
+                          </object>
+                        </child>
                       </object>
                     </child>
                   </object>
@@ -2708,6 +2726,81 @@ Suspendisse feugiat quam quis dolor accumsan cursus. </property>
       </object>
     </child>
   </object>
+  <object class="GtkMessageDialog" id="info_dialog">
+    <property name="transient-for">window</property>
+    <property name="modal">True</property>
+    <property name="text" translatable="yes">Do something?</property>
+    <property name="secondary-text" translatable="yes">If you do something,
+bad things might happen.</property>
+    <child type="action">
+      <object class="GtkButton" id="cancel_info_dialog">
+        <property name="visible">True</property>
+        <property name="label" translatable="yes">Cancel</property>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="doit_info_dialog">
+        <property name="visible">True</property>
+        <property name="label" translatable="yes">Do It</property>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="cancel">cancel_info_dialog</action-widget>
+      <action-widget response="ok">doit_info_dialog</action-widget>
+    </action-widgets>
+  </object>
+  <object class="GtkDialog" id="action_dialog">
+    <property name="transient-for">window</property>
+    <property name="modal">True</property>
+    <property name="use-header-bar">1</property>
+    <property name="title" translatable="yes">Action</property>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="margin">20</property>
+            <property name="label" translatable="yes">Bla bla bla</property>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="cancel_action_dialog">
+        <property name="visible">True</property>
+        <property name="label" translatable="yes">Cancel</property>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="act_action_dialog">
+        <property name="visible">True</property>
+        <property name="can-default">True</property>
+        <property name="has-default">True</property>
+        <property name="label" translatable="yes">Action</property>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="cancel">cancel_action_dialog</action-widget>
+      <action-widget response="ok" default="true">act_action_dialog</action-widget>
+    </action-widgets>
+  </object>
+  <object class="GtkDialog" id="preference_dialog">
+    <property name="transient-for">window</property>
+    <property name="modal">True</property>
+    <property name="use-header-bar">1</property>
+    <property name="title" translatable="yes">Properties</property>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="margin">20</property>
+            <property name="label" translatable="yes">Bla bla bla</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
   <object class="GtkSizeGroup">
     <property name="mode">vertical</property>
     <widgets>